/*
 * Copyright 2011 yura.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.opu.db_vdumper.actions.view;

import java.awt.event.ActionEvent;
import java.util.Locale;
import javax.swing.ButtonGroup;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
import net.infonode.docking.theme.DockingWindowsTheme;
import org.opu.db_vdumper.actions.AbstractAction;
import org.opu.db_vdumper.ui.MainView;
import org.opu.db_vdumper.ui.ThemeManager;

/**
 *
 * @author yura
 */
public abstract class ThemeAction extends AbstractAction {

    @Override
    protected void setText(Locale locale) {
        // Do nothing.
    }

    public static JMenu getThemeMenu(final MainView view, String name) {
        JMenu themesMenu = new JMenu(name);

        ButtonGroup group = new ButtonGroup();

        for (final DockingWindowsTheme theme : ThemeManager.themes()) {
            JMenuItem item = themesMenu.add(new JRadioButtonMenuItem(new ThemeAction() {

                @Override
                public String getName() {
                    return theme.getName();
                }

                @Override
                public void action(ActionEvent e) {
                    view.setTheme(theme);
                }
            }));

            if (view.getTheme().getClass() == theme.getClass()) {
                item.setSelected(true);
            }

            group.add(item);
        }

        return themesMenu;
    }
}
